#include <stdlib.h>
#include <string.h>
#include <openssl/evp.h>

 int main(void) {

     char plaintext[1024] = "Hello World?";
     char ciphertext[1024];
     char mykey[EVP_MAX_KEY_LENGTH] = "this's my key";
     char iv[EVP_MAX_IV_LENGTH] = "my iv";
     int in_len, out_len=0;
     EVP_CIPHER_CTX ctx;

     in_len = strlen(plaintext);

     printf("No encrypt: %s\n", plaintext);

     EVP_EncryptInit(&ctx, EVP_aes_128_cbc(), mykey, iv);
     EVP_EncryptUpdate(&ctx, ciphertext, &out_len, plaintext, in_len);
     EVP_EncryptFinal(&ctx, &ciphertext[out_len], &out_len);

     printf("Encrypted : %s\n", ciphertext);

     EVP_DecryptInit(&ctx, EVP_aes_128_cbc(), mykey, iv);
     EVP_DecryptUpdate(&ctx, plaintext, &in_len, ciphertext, out_len);
     EVP_DecryptFinal(&ctx, &plaintext[in_len], &in_len);

     printf("Decrypted : %s\n", plaintext);

     exit(1);
}
